<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-row>
      <el-col :span='22' :xs='24'>
        <el-form ref="form" :model="quo_price" :rules="rules" label-width="100px" id="mvcfm">
          <el-button @click="addProcurementContractSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
          <el-button @click="gotoPage('/psi/supplychainmana/ProcurementContractS?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>返回</el-button>
          <div class="form-unit">
            <span class="mvc-title-left"> 添加新合同 </span>
          </div>
          <div>
            <el-row>
              <el-col :span="24">
                <el-form-item label="合同条形码" prop="quo_barcode">
                  {{quo_price.bar}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="合同编号" prop="quo_num">
                  <el-input v-model="quo_price.quo_num" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="合同主题" prop="quo_theme">
                  <el-input v-model="quo_price.quo_theme" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="供应商" prop="">
                  {{quo_price.quo_client}}
                  <el-button @click="popSelectionSuppliers('','quo_client')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="联系人" prop="">
                  {{quo_price.quo_contact}}
                  <el-button @click="popChooseContacts('','quo_contact')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="供应商地址" prop="quo_address">
                  <el-input type="textarea" v-model="quo_price.quo_address" ttparea=350></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="签订日期" prop="quo_pacttime">
                  <el-date-picker v-model="quo_price.quo_pacttime" type="date" style='width:100%' value-format="yyyy-MM-dd" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="失效日期 " prop="quo_faildate">
                  <el-date-picker v-model="quo_price.quo_faildate" type="date" style='width:100%' value-format="yyyy-MM-dd" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <div class="form-unit">
            <span class="mvc-title-left"> 列表条目 </span>
          </div>
          <el-table :data="s_top">
            <el-table-column label="操作" prop="" width="60">
              <template slot-scope="scope">
                <el-link @click="appendRow(s_top,scope)" type='primary'><i class='el-icon-plus' title='增加行' /></el-link>
                <el-link @click="delRow(s_top,scope)" type='danger'><i class='el-icon-minus' title='删除行' /></el-link>
              </template>
            </el-table-column>
            <el-table-column label="产品选择" prop="product_id">
              <template slot-scope="scope">
                {{scope.row.product_id}}
              </template>
            </el-table-column>
            <el-table-column label="数量" prop="">
              <template slot-scope="scope">
                <el-input v-model="scope.row.pronum_no" />
              </template>
            </el-table-column>
            <el-table-column label="单价" prop="price_pro">
              <template slot-scope="scope">
                <el-input v-model="scope.row.price_pro" />
              </template>
            </el-table-column>
            <el-table-column label="交货地点" prop="" width="50">
              <template slot-scope="scope">
                <el-input v-model="scope.row.pronum_address" />
              </template>
            </el-table-column>
            <el-table-column label="交货时间" prop="">
              <template slot-scope="scope">
                <el-date-picker v-model="scope.row.pronum_endate" type="date" style='width:100%' value-format="yyyy-MM-dd" />
              </template>
            </el-table-column>
            <el-table-column label="简要描述" prop="" width="20">
              <template slot-scope="scope">
                <el-input v-model="scope.row.pronum_remark" />
              </template>
            </el-table-column>
          </el-table>
          <div class="form-unit">
            <span class="mvc-title-left"> 甲乙双方责任 </span>
          </div>
          <el-table :data="s_top">
            <el-table-column label="操作" prop="" width="60">
              <template slot-scope="scope">
                <el-link @click="appendRow(s_top,scope)" type='primary'><i class='el-icon-plus' title='增加行' /></el-link>
                <el-link @click="delRow(s_top,scope)" type='danger'><i class='el-icon-minus' title='删除行' /></el-link>
              </template>
            </el-table-column>
            <el-table-column label="选择" prop="description">
              <template slot-scope="scope">
                {{scope.row.description}}
              </template>
            </el-table-column>
          </el-table>
          <div class="form-unit">
            <span class="mvc-title-left"> 付款方式 </span>
          </div>
          <el-table :data="s_top">
            <el-table-column label="操作" prop="" width="60">
              <template slot-scope="scope">
                <el-link @click="appendRow(s_top,scope)" type='primary'><i class='el-icon-plus' title='增加行' /></el-link>
                <el-link @click="delRow(s_top,scope)" type='danger'><i class='el-icon-minus' title='删除行' /></el-link>
              </template>
            </el-table-column>
            <el-table-column label="首次付款" prop="pay_first">
              <template slot-scope="scope">
                <el-input v-model="scope.row.pay_first" />
              </template>
            </el-table-column>
            <el-table-column label="二次付款" prop="pay_sec">
              <template slot-scope="scope">
                <el-input v-model="scope.row.pay_sec" />
              </template>
            </el-table-column>
            <el-table-column label="尾付款" prop="pay_end">
              <template slot-scope="scope">
                <el-input v-model="scope.row.pay_end" />
              </template>
            </el-table-column>
          </el-table>
          <div class="form-unit">
            <span class="mvc-title-left"> 付款账号 </span>
          </div>
          <el-table :data="s_top">
            <el-table-column label="操作" prop="" width="60">
              <template slot-scope="scope">
                <el-link @click="appendRow(s_top,scope)" type='primary'><i class='el-icon-plus' title='增加行' /></el-link>
                <el-link @click="delRow(s_top,scope)" type='danger'><i class='el-icon-minus' title='删除行' /></el-link>
              </template>
            </el-table-column>
            <el-table-column label="账号选择" prop="bank">
              <template slot-scope="scope">
                {{scope.row.bank}}
                <el-button @click="popPaymentSelection('bank','bank')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="form-unit">
            <span class="mvc-title-left"> 违约责任 </span>
          </div>
          <el-table :data="s_top">
            <el-table-column label="操作" prop="" width="60">
              <template slot-scope="scope">
                <el-link @click="appendRow(s_top,scope)" type='primary'><i class='el-icon-plus' title='增加行' /></el-link>
                <el-link @click="delRow(s_top,scope)" type='danger'><i class='el-icon-minus' title='删除行' /></el-link>
              </template>
            </el-table-column>
            <el-table-column label="责任选择" prop="break_duty">
              <template slot-scope="scope">
                {{scope.row.break_duty}}
              </template>
            </el-table-column>
          </el-table>
          <div class="form-unit">
            <span class="mvc-title-left"> 其他要求 </span>
          </div>
          <el-table :data="s_top">
            <el-table-column label="操作" prop="" width="60">
              <template slot-scope="scope">
                <el-link @click="appendRow(s_top,scope)" type='primary'><i class='el-icon-plus' title='增加行' /></el-link>
                <el-link @click="delRow(s_top,scope)" type='danger'><i class='el-icon-minus' title='删除行' /></el-link>
              </template>
            </el-table-column>
            <el-table-column label="选择" prop="description">
              <template slot-scope="scope">
                {{scope.row.description}}
              </template>
            </el-table-column>
          </el-table>
          <div>
          </div>
          <div class="form-unit">
            <span class="mvc-title-left"> 合同 </span>
          </div>
          <div>
            <el-row>
              <el-col :span="24">
                <el-form-item label="内部描述" prop="quo_insides">
                  <el-input type="textarea" v-model="empty" ttparea=350></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
              </el-col>
            </el-row>
          </div>
          <el-button @click="addProcurementContractSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
          <el-button @click="gotoPage('/psi/supplychainmana/ProcurementContractS?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>返回</el-button>
        </el-form>
      </el-col>
      <el-col :span='2' :xs='24'>
        <el-menu default-active='active' class='menu-unit'>
          <el-menu-item v-for='item in Container'>
            <el-link @click="gotoMenu(item.url)" :type="'采购合同'===item.name?'primary':'default'">{{item.page_desc||item.name}}</el-link>
          </el-menu-item>
        </el-menu>
      </el-col>
    </el-row>
    <el-dialog :visible.sync="SelectionSuppliersVisible" append-to-body>
      <SelectionSuppliers v-if="SelectionSuppliersVisible" ref="SelectionSuppliers" :popparams="popparams"> </SelectionSuppliers>
    </el-dialog>
    <el-dialog :visible.sync="ChooseContactsVisible" append-to-body>
      <ChooseContacts v-if="ChooseContactsVisible" ref="ChooseContacts" :popparams="popparams"> </ChooseContacts>
    </el-dialog>
    <el-dialog :visible.sync="PaymentSelectionVisible" append-to-body>
      <PaymentSelection v-if="PaymentSelectionVisible" ref="PaymentSelection" :popparams="popparams"> </PaymentSelection>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import SelectionSuppliers from "@/views/psi/supplychainmana/SelectionSuppliers";
  import ChooseContacts from "@/views/psi/supplychainmana/ChooseContacts";
  import PaymentSelection from "@/views/psi/supplychainmana/PaymentSelection";
  export default {
    name: 'AddProcurementContract',
    components: {
      SelectionSuppliers,
      ChooseContacts,
      PaymentSelection,
    },
    props: ['popparams'],
    data() {
      return {
        SelectionSuppliersVisible: false,
        SelectionSuppliersValue: null,
        SelectionSuppliersDesc: null,
        ChooseContactsVisible: false,
        ChooseContactsValue: null,
        ChooseContactsDesc: null,
        PaymentSelectionVisible: false,
        PaymentSelectionValue: null,
        PaymentSelectionDesc: null,
        vueparams: this.getVUEParams(""),
        quo_price: {
          bar: null,
          quo_num: null,
          quo_theme: null,
          quo_client: null,
          quo_contact: null,
          quo_address: null,
          quo_pacttime: null,
          quo_faildate: null,
        },
        s_top: [],
        loading: false,
        Container: null,
        rules: {
          quo_num: [{
            required: true,
            message: "合同编号不能为空",
            trigger: 'blur',
          }],
          quo_theme: [{
            required: true,
            message: "合同主题不能为空",
            trigger: 'blur',
          }],
          quo_faildate: [{
            required: true,
            message: "失效日期 不能为空",
            trigger: 'blur',
          }],
        }
      }
    },
    created() {
      this.getData();
      this.loadContainerMenu({
        pid: "821959E4C08E497BA9C4B10D9571712F",
        name: "采购任务右菜单",
        selected: "采购合同"
      }, 'Container', this.vueparams);
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/psi/supplychainmana/ProcureSupplyAction/addProcurementContract?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      addProcurementContractSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/psi/supplychainmana/ProcureSupplyAction/addProcurementContractSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/psi/supplychainmana/ContractDetails/contractDetails?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      contractAddPageSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/psi/supplychainmana/ProcureSupplyAction/contractAddPageSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/psi/supplychainmana/ContractDetails/contractDetails?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      popSelectionSuppliers(desc, value) {
        this.SelectionSuppliersVisible = true;
        this.SelectionSuppliersDesc = desc;
        this.SelectionSuppliersValue = value;
      },
      closeSelectionSuppliers(value, desc) {
        this.SelectionSuppliersVisible = false;
        this.$set(this.quo_price, this.SelectionSuppliersDesc, desc);
        this.$set(this.quo_price, this.SelectionSuppliersValue, value);
      },
      popChooseContacts(desc, value) {
        this.ChooseContactsVisible = true;
        this.ChooseContactsDesc = desc;
        this.ChooseContactsValue = value;
      },
      closeChooseContacts(value, desc) {
        this.ChooseContactsVisible = false;
        this.$set(this.quo_price, this.ChooseContactsDesc, desc);
        this.$set(this.quo_price, this.ChooseContactsValue, value);
      },
      popPaymentSelection(desc, value) {
        this.PaymentSelectionVisible = true;
        this.PaymentSelectionDesc = desc;
        this.PaymentSelectionValue = value;
      },
      closePaymentSelection(value, desc) {
        this.PaymentSelectionVisible = false;
        this.$set(this.s_top, this.PaymentSelectionDesc, desc);
        this.$set(this.s_top, this.PaymentSelectionValue, value);
      },
    },
  }
</script>
